import fang from '../../models/Fang';
import Cache from '../../utils/Cache';

Page({
  data: {
    fangs: [],
    page: 1,
    topShow: true
  },
  onLoad(options) {
    this.getMore();
  },
  onPullDownRefresh() {
    this.getMore();
  },
  onReachBottom() {
    this.getMore();
  },
  getMore() {
    if (!Cache.has('rentedList')) {
      let page = this.data.page;

      fang.rented(page).then( ret => {
        if (ret.data.data.data.length > 0) {
          this.setData({
            fangs: [ ...this.data.fangs, ...ret.data.data.data],
            page: ++page
          })
        } else {
          Cache.set('rentedList',true,10);
          wx.showToast({
            title: '没有更多最新的数据了',
            icon: 'none',
            duration: 1500,
            mask: true,
          });
        }
      });
    }
  },
  onPageScroll(evt) {
    let topShow = true;
    if (evt.scrollTop > 100) {
      topShow = false;
    }
    this.setData({ topShow });
  },

  goTo() {
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 300
    });
  }

})